package ProductAndConsumer;

public class Consumer implements Runnable {
    private Num num;

    public Num getNum() {
        return num;
    }

    public void setNum(Num num) {
        this.num = num;
    }

    public Consumer(Num num) {
        this.num = num;
    }

    public Consumer() {
    }

    @Override
    public void run() {
        while (true) {
            synchronized (this.num) {
                if (this.num.getNum() % 2 == 1) {
                    try {
                        this.num.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                this.num.setNum(this.num.getNum() + 1);
                try {
                    Thread.sleep(1000 * 1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + " -----> " + this.num.getNum());
                this.num.notifyAll();

            }
        }
    }
}
